package com.example.controller;

import com.example.Utils.UserHolder;
import com.example.model.Result;
import com.example.model.User;
import com.example.modelDTO.OrderUserDTO;
import com.example.service.impl.OrderUserServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Hello
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/orderUser")
@Api
public class OrderUserController {

    @Autowired
    OrderUserServiceImpl orderUserService;
    //获得所有订单
    /*@GetMapping("/getAll")
    public Result<List<OrderUserDTO>> getAll(){
        return Result.success(orderUserService.getAll());
    }

    @GetMapping("/getAllDingin")
    public Result<List<OrderUserDTO>> getAllDingin(){
        return Result.success(orderUserService.getAllDingin());
    }

    @GetMapping("/getAllTakeAway")
    public Result<List<OrderUserDTO>> getAllTakeAway(){
        return Result.success(orderUserService.getAllTakeAway());
    }
*/
    @GetMapping("/getAllById")
    public Result<List<OrderUserDTO>> getAllById(){
        System.out.println("controller be called");
        User loginUser =UserHolder.getUser();
        System.out.println("loginUserId:"+loginUser.getUserId());
        return Result.success(orderUserService.getAllById(loginUser.getUserId()));
    }

    @GetMapping("/getAllDinginById")
    public Result<List<OrderUserDTO>> getAllDinginById(){
        User loginUser = UserHolder.getUser();
        return Result.success(orderUserService.getAllDinginById(loginUser.getUserId()));
    }

    @GetMapping("/getAllTakeAwayById")
    public Result<List<OrderUserDTO>> getAllTakeAwayById(){
        User loginUser=UserHolder.getUser();
        return Result.success(orderUserService.getAllTakeAwayById(loginUser.getUserId()));
    }
}
